home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98b.txt / 000120_icon-group-sender _Tue Jun 30 08:00:45 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.8/8.8.7) with SMTP id IAA28503
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Tue, 30 Jun 1998 08:00:45 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA00768; Tue, 30 Jun 1998 08:00:32 -0700
  7. Date: Tue, 30 Jun 1998 08:23:23 -0500 (CDT)
  8. From: Chris Tenaglia <cdt@post.its.mcw.edu>
  9. To: icon-group@optima.CS.Arizona.EDU
  10. Subject: sample CGI
  11. Message-Id: <Pine.SOL.3.96.980630081906.29720A-100000@post.its.mcw.edu>
  12. Mime-Version: 1.0
  13. Content-Type: TEXT/PLAIN; charset=US-ASCII
  14. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  15. Status: RO
  16. Content-Length: 2869
  17.  
  18. This CGI stuff is a snap once you get the hang of it. Here's a
  19. sample. This is a CGI to return the time remainting till the
  20. turn of the century. It also records visits in a logfile.
  21. I was able to run it at http://www.mcw.edu/cgi-bin/bioet/cdown
  22. where it will be for a few days. As usual the file permissions
  23. are the most sensitive issue. Here's the source;
  24. _______________________________________________________________
  25.  
  26. #
  27. # file : cdown.icn
  28. # desc : This program returns countdown information till
  29. #        the turn of the century
  30. # use  : to be called by a cgi script in a web page : .../cgi-bin/cdown
  31. # note : 730 days from 1/1/1998 to 1/1/2000
  32. #
  33. # update          by          what
  34. # 29-jun-1998     tenaglia    initial write
  35. #
  36. procedure main()
  37.   write("content-type: text/html")
  38.   write()
  39.   write("<HTML>")
  40.   write("<HEAD>")
  41.   write("<TITLE>")
  42.   write("Century Countdown")
  43.   write("</TITLE>")
  44.   write("</HEAD>")
  45.   write("<BODY BGCOLOR=#ffffff>")
  46.   write("<CENTER><FONT COLOR=#c00000>")
  47.   write("<H1>Century CountDown !</H1>")
  48.   write("<P>")
  49.  
  50.   write("<TABLE border=10>")
  51.   write("<TH><H3><FONT COLOR=#800080>")
  52.   write("Today is ",&dateline,"</TH>")
  53.  
  54. #
  55. # gather the time fields from the current moment
  56. #
  57.   date := &date
  58.   time := &clock
  59.   delta:= [0,31,59,90,120,151,181,212,243,273,304,334,365]
  60.  
  61.   year := parse(date,'/')[1]
  62.   month:= parse(date,'/')[2]
  63.   day  := parse(date,'/')[3]
  64.  
  65.   hour := parse(time,':')[1]
  66.   min  := parse(time,':')[2]
  67.   sec  := parse(time,':')[3]
  68.  
  69. #
  70. # calculate the time left until 1/1/2000
  71. #
  72.   diff    := (year - 1998) * 365 + delta[month] + day
  73.   remains := 730 - diff
  74.   part1   :=  24 - hour
  75.   part2   :=  60 - min
  76.   part3   :=  60 - sec
  77.  
  78.   write("<TR><TD><FONT COLOR=#800080><CENTER>There are ",remains," days,</CENTER></TD></TR>")
  79.   write("<TR><TD><FONT COLOR=#800080><CENTER>And ",part1," hours,</CENTER></TD></TR>",
  80.         "<TR><TD><FONT COLOR=#800080><CENTER>",part2," minutes,<CENTER></TD></TR>",
  81.         "<TR><TD><FONT COLOR=#800080><CENTER>",part3," seconds until 2000 A.D.</CENTER></TD></TR>")
  82.   write("</FONT></TABLE>")
  83.   write("<P></FONT>")
  84.   write("</BODY>")
  85.   write("</HTML>")
  86.  
  87. #
  88. # record visits
  89. #
  90.   computer:= getenv("REMOTE_ADDR")
  91.   logfile := open("cdown.log","a")
  92.   write(logfile,"CDOWN accessed ",&dateline," from ",computer)
  93.   close(logfile)
  94.  
  95.   end
  96.  
  97. #
  98. # parse a string into a list with respect to a delimiter
  99. #
  100. procedure parse(line,delims)
  101.   static chars
  102.   chars  := &cset -- delims
  103.   tokens := []
  104.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  105.   return tokens
  106.   end
  107.  
  108. _______________________________________________________________
  109. Chris Tenaglia   (system manager)     |  The future foretold,
  110. Medical College of Wisconsin          |  The past explained,
  111. 8701 W. Watertown Plank Rd.           |  The present largely appologized for.
  112. Milwaukee, WI 53226   (414)456-8765   |  Organon to the Doctor
  113.  
  114.  
  115.